Home:ALL Converter>Is there a function similar to std::lower_bound without needing a sorted/partitioned input?

Is there a function similar to std::lower_bound without needing a sorted/partitioned input?

Ask Time:2020-02-24T00:50:32         Author:24n8

Json Formatter

Is there a STL function that returns an iterator or index to the smallest element greater than some input value in an unsorted array. std::lower_bound doesn't work because it requires partitioning, and my array is not partitioned according to its requirements.

For example,

int main(int argc, char const *argv[])
{
   vector<int> vec{5,1,2,9,1,5,3};

   std::cout << std::lower_bound(vec.begin(), vec.end(), 2) - vec.begin() << std::endl;
}

The output here is 3 when I want it to be 6 corresponding to vec[6].

Author:24n8,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60364543/is-there-a-function-similar-to-stdlower-bound-without-needing-a-sorted-partiti
yy